package com.scwatch.ext.web.back;


import com.alibaba.fastjson.JSONObject;
import com.scwatch.common.web.Servlets;
import com.scwatch.core.constant.Constants;
import com.scwatch.core.domain.Site;
import com.scwatch.core.domain.User;
import com.scwatch.core.service.OperationLogService;
import com.scwatch.core.support.Backends;
import com.scwatch.core.support.Context;
import com.scwatch.ext.domain.ClickRate;
import com.scwatch.ext.domain.StartPage;
import com.scwatch.ext.service.ShareClickRateService;
import com.scwatch.ext.service.StartPageService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.scwatch.core.constant.Constants.*;

/**
 * @title : 分享页点击量
 */
@Controller
@RequestMapping("/ext/click_rate")
public class ClickRateController {
    private static final Logger logger = LoggerFactory.getLogger(ClickRateController.class);

    @Autowired
    private ShareClickRateService service;

    @Autowired
    private OperationLogService logService;




    @RequiresPermissions("ext:click_rate:list")
    @RequestMapping("list.do")
    public String list(HttpServletRequest request, org.springframework.ui.Model modelMap) {
        List<ClickRate> rateList = service.findAll();
        if(rateList!=null && rateList.size()>0){
            modelMap.addAttribute("bean", rateList.get(0));
        }else{
            modelMap.addAttribute("bean", null);
        }
        return "ext/click_rate/click_rate_page";
    }


    @RequiresPermissions("ext:click_rate:update")
    @RequestMapping("edit.do")
    public String edit(Integer id, Integer isOpen,
                       HttpServletRequest request, org.springframework.ui.Model modelMap) {
        Site site = Context.getCurrentSite();
        User user = Context.getCurrentUser();
        ClickRate bean = new ClickRate();
        bean.setUser(user);
        bean.setSite(site);
        bean.setIsOpen(isOpen);
        if(id!=null){
            bean.setId(id);
        }
        bean = service.save(bean);
        modelMap.addAttribute("bean", bean);
        return "ext/click_rate/click_rate_page";
    }


}
